/**
 * Copyright 2022 meituan.com Inc. All Rights Reserved.
 */
package org.example.server.context;

import org.example.api.Dog;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 *
 * @author zhangxiaofan08
 * @version 1.0 2022/3/1
 */
@Component
public class DogContextHolder implements InitializingBean, ApplicationContextAware {
 private ApplicationContext applicationContext;

 @Override
 public void afterPropertiesSet() throws Exception {
  init();
 }

 private void init() {
  //todo 数据库加载之前配置过的jar
  Map<String, Dog> map = applicationContext.getBeansOfType(Dog.class);
  DogContext.setAll(map);
 }

 @Override
 public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
  this.applicationContext = applicationContext;
 }
}
